import Mock from "mockjs";
import users from "../data/user";
import orgs from "../data/orgs";
import { getRandomItems } from "../util/utils";
export default {
  async getFormList(ctx: any) {
    const params = ctx.request.body;
    const list = Mock.mock({
      "list|30": [
        {
          "id|+1": 0,
          "version|1-100": 0,
          createTime: "@createDate",
          updateTime: "@datetime",
          updateCode: "@name",
          createUserCode: "@name",
          tenantCode: "annto",
          onlineTmplNo: /\d{5,10}/,
          onlineTmplName: "@ctitle(6,10)",
          onlineTmplDesc: "@ctitle(10,20)",
          onlineTmplQrcodeUrl: "url",
          "useFlag|0-1": 0, // 0专用 1通用
          "enabledFlag|0-1": 0, // 0失效 1生产
          "approvalFlag|0-1": 0, // 0不需要审批 1需要审批
        },
      ],
      offset: 0,
      pageNo: params.pageNo,
      pageSize: params.pageSize,
      totalCount: 10000,
      totalPage: 10000,
    });

    ctx.body = {
      code: "0",
      data: list,
      msg: "Success",
      errMsg: null,
    };
  },
  async detail(ctx: any) {
    const list = Mock.mock({
      "list|10": [
        {
          "id|+1": 1,
          name: "@ctitle(6,10)",
          "age|1-100": 1,
          email: "@email",
        },
      ],
    });
    ctx.body = {
      code: "0",
      data: list,
    };
  },
  async updateUseFlag(ctx: any) {
    const params = ctx.request.body;
    if (params.id % 3 === 0) {
      ctx.body = {
        code: "1",
        msg: "操作失败",
      };
      return;
    }
    ctx.body = {
      code: "0",
      msg: "操作成功",
      params: params,
    };
  },
  async createForm(ctx: any) {
    const params = ctx.request.body;
    ctx.body = {
      code: "0",
      msg: "创建成功",
      params: params,
    };
  },
  async updateForm(ctx: any) {
    const params = ctx.request.body;
    ctx.body = {
      code: "0",
      msg: "创建成功",
      params: params,
    };
  },
  async getSelectedOrgs(ctx: any) {
    const params = ctx.request.body;
    ctx.body = {
      code: "0",
      msg: "操作成功",
      data: getRandomItems(orgs, "3-10"),
    };
  },
  async getSelectedUsers(ctx: any) {
    const params = ctx.request.body;
    ctx.body = {
      code: "0",
      msg: "创建成功",
      data: getRandomItems(users, "2-10"),
    };
  },
  async getAuditList(ctx: any) {
    const params = ctx.request.body;
    if (params.id % 3 === 0) {
      ctx.body = {
        code: "0",
        msg: "操作失败",
        data: null,
      };
      return;
    }

    const res = getRandomItems(users, 2);
    const org = getRandomItems(orgs, 2);
    const list = Mock.mock({
      "list|0-3": [
        {
          "id|+1": 0,
          "version|1-100": 0,
          createTime: "@createDate",
          updateTime: "@datetime",
          updateCode: "@name",
          createUserCode: "@name",
          tenantCode: "annto",
          "approvalProcessSort|+1": 0,
          "approvalType|1-2": 0, // 审批模式 2 部门负责人
          approvalUserCode: res[0].userCode,
          approvalUserName: res[0].userName,
          approvalOrgCode: org[0].orgCode,
          approvalOrgName: org[0].orgName,
          "approvalNotifyEmailFlag|0-1": 0, // 0 不通知 1 通知,
          "approvalNotifyAppletFlag|0-1": 0, // 0 不通知 1 通知,
          ccUserCode: res[1].userCode,
          ccUserName: res[1].userName,
          "ccNotifyEmailFlag|0-1": 0, // 0 不通知 1 通知,
          "ccNotifyAppletFlag|0-1": 0, // 0 不通知 1 通知,
        },
      ],
      offset: 0,
      pageNo: params.pageNo,
      pageSize: params.pageSize,
      totalCount: 10000,
      totalPage: 10000,
    });

    ctx.body = {
      code: "0",
      data: list.list,
      msg: "Success",
      errMsg: null,
    };
  },
};
